#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include "rngs.h"
#include "testhelpers.c"

// This function tests steward

void setHand(struct gameState *state){
    state->hand[0][0] = steward;
    state->handCount[0] = 1;
}

//steward choices depend on effect 1: +2 cards  2: +2 coins, 3: trash 2 cards
int main(){
    struct gameState *state = malloc(sizeof(struct gameState));
    setState(state);
    resetDeck(state);
    setHand(state);

    printf("starting Steward Card Effect Test\n");

    resetFlag();

    cardEffect(steward, 1, 0, 0, state, 0, 0);
    if(state->handCount[0] != 2)
        assertMessage("Handcount should be %d but it is %d\n", 2, state->handCount[0]);
    if(state->playedCardCount != 1)
        assertMessage("Played Card Count should be %d but it is %d\n", 1, state->playedCardCount);
    if(state->playedCards[0] != steward)
        assertMessage("Played Card should be %d but it is %d\n", steward, state->playedCards[0]);

    free(state);
    state = malloc(sizeof(struct gameState));
    setState(state);
    resetDeck(state);
    setHand(state);

    cardEffect(steward, 2, 0, 0, state, 0, 0);
    if(state->handCount[0] != 0)
        assertMessage("Handcount should be %d but it is %d\n", 0, state->handCount[0]);
    if(state->playedCardCount != 1)
        assertMessage("Played Card Count should be %d but it is %d\n", 1, state->playedCardCount);
    if(state->playedCards[0] != steward)
        assertMessage("Played Card should be %d but it is %d\n", steward, state->playedCards[0]);
    if(state->coins != 2)
        assertMessage("Coins should be %d but it is %d\n", 2, state->coins);

    free(state);
    state = malloc(sizeof(struct gameState));
    setState(state);
    resetDeck(state);
    setHand(state);

    cardEffect(steward, 3, 0, 0, state, 0, 0);
    if(state->handCount[0] != 0)
        assertMessage("Handcount should be %d but it is %d\n", 0, state->handCount[0]);
    if(state->playedCardCount != 1)
        assertMessage("Played Card Count should be %d but it is %d\n", 1, state->playedCardCount);
    if(state->playedCards[0] != steward)
        assertMessage("Played Card should be %d but it is %d\n", steward, state->playedCards[0]);

    free(state);
    state = malloc(sizeof(struct gameState));
    setState(state);
    resetDeck(state);
    setHand(state);

    state->hand[0][1] = estate;
    state->handCount[0] = 2;

    cardEffect(steward, 3, 1, 0, state, 0, 0);
    if(state->handCount[0] != 0)
        assertMessage("Handcount should be %d but it is %d\n", 0, state->handCount[0]);
    if(state->playedCardCount != 2)
        assertMessage("Played Card Count should be %d but it is %d\n", 2, state->playedCardCount);
    if(state->playedCards[0] != steward)
        assertMessage("Played Card should be %d but it is %d\n", steward, state->playedCards[0]);

    free(state);
    state = malloc(sizeof(struct gameState));
    setState(state);
    resetDeck(state);
    setHand(state);

    state->hand[0][1] = estate;
    state->hand[0][2] = copper;
    state->handCount[0] = 3;

    cardEffect(steward, 3, 1, 2, state, 0, 0);
    if(state->handCount[0] != 0)
        assertMessage("Handcount should be %d but it is %d\n", 0, state->handCount[0]);
    if(state->playedCardCount != 3)
        assertMessage("Played Card Count should be %d but it is %d\n", 3, state->playedCardCount);
    if(state->playedCards[0] != steward)
        assertMessage("Played Card should be %d but it is %d\n", steward, state->playedCards[0]);

    if(testState() == 0)
        printf("Steward Card Effect Test Passed\n");
    else
        printf("Steward Card Effect Test Failed\n");

    free(state);
    return 0;
}
